package server

import (
	"rpc/model"
	"rpc/proto/goods"
)

func GoodCreate(in *goods.GoodsCreateReq) (*model.Goods, error) {
	stu := model.Goods{
		GoodsId:    in.GoodsId,
		GoodsName:  in.GoodsName,
		GoodsNum:   in.GoodsNum,
		GoodsPrice: in.GoodsPrice,
		GoodsImage: in.GoodsImage,
	}
	err := stu.GoodsCreate()
	if err != nil {
		return nil, err
	}
	return &stu, nil
}
func GoodsDelete(in *goods.DeleteGoodsReq) (*model.Goods, error) {
	stu := &model.Goods{
		GoodsId: in.GoodsId,
	}
	err := stu.DeleteGoods()
	if err != nil {
		return nil, err
	}
	return stu, nil
}
func GetGoods(in *goods.GoodsListReq) ([]model.Goods, error) {
	stu := &model.Goods{}
	getGoods, err := stu.GetGoods()
	if err != nil {
		return nil, err
	}
	return getGoods, nil
}
func UpdateGoods(in *goods.UpdateGoodsReq) (*model.Goods, error) {
	stu := model.Goods{
		GoodsId:  in.GoodsId,
		GoodsNum: in.GoodNum,
	}
	err := stu.UpdateGoods()
	if err != nil {
		return nil, err
	}
	return &stu, nil
}
